package com.mceil.mceilbase.activity;

import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.mceil.mceilbase.R;
import com.mceil.mceilbase.adapter.DaliyAdapter;
import com.mceil.mceilbase.bean.DaliyBean;
import com.mceil.mylibrary.annotation.ContentView;
import com.mceil.mylibrary.annotation.ViewInject;
import com.mceil.mylibrary.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

@ContentView(R.layout.activity_daliy)
public class DaliyActivity extends BaseActivity {

    @ViewInject(R.id.toolbar)
    TitleBar toolBar;

    @ViewInject(R.id.recycler_view)
    RecyclerView recyclerView;

    @Override
    protected void initPreferences() {

    }

    @Override
    protected void initView() {
        toolBar.setTitle("日常记录");
        toolBar.setRightTitle("新增");

        toolBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(TitleBar titleBar) {
                finish();
            }

            @Override
            public void onTitleClick(TitleBar titleBar) {
                OnTitleBarListener.super.onTitleClick(titleBar);
            }

            @Override
            public void onRightClick(TitleBar titleBar) {
                OnTitleBarListener.super.onRightClick(titleBar);
            }
        });
    }

    @Override
    protected void initData() {
        List<DaliyBean> mDatas =new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            mDatas.add(new DaliyBean());
        }
        initList(mDatas);
    }

    private void initList(List<DaliyBean> mDatas) {
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        DaliyAdapter adapter = new DaliyAdapter(R.layout.item_daliy,mDatas);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                Intent intent = new Intent(DaliyActivity.this,DaliyDetialActivity.class);
                startActivity(intent);
            }
        });
    }
}
